package com.ilove.media.frame;

import org.kalmeo.kuix.core.Kuix;
import org.kalmeo.kuix.core.KuixConstants;
import org.kalmeo.kuix.widget.Screen;
import org.kalmeo.util.frame.Frame;
import com.ilove.core.ILOVEContants;
import com.ilove.model.SMSender;

public class SendGiftFrame implements Frame {

	public static SendGiftFrame instance = new SendGiftFrame();
	public int id;// 0 text data from vas, 1 ringtone, 2 game ,3 wallpaper
	public String contentId;
	public String contentName;

	public String[] vecContent = null;
	// private String closeDivTag = "</div>";
	boolean isShort = false;
	// MainFrame's Screen
	private Screen screen;
	String message = "";
	String destination = "";
	public void onAdded() {
		// TODO Auto-generated method stub
		screen = Kuix.loadScreen(ILOVEContants.SENDGIFT_SCREEN, null);
		screen.setCurrent();
	}

	public boolean onMessage(Object identifier, Object[] arg1) {
	
		if ("gift".equals(identifier)) {
			System.out.println("Send gift");
			String phonenumber = (String) arg1[0];
			if (id == 1) {
				message = "NC " +phonenumber +" " + contentId;
				destination = "7585";
			} else if (id == 2) {
				message = "GA "  +phonenumber +" "+ contentId;
				destination = "7785";
			} else if (id == 3) {
				message = "HN "  +phonenumber +" "+ contentId;
				destination = "7785";
			}
			Kuix.alert(	"Bạn gửi tặng phải trả phí (15000 đồng). Bạn có đồng ý ko?)",
							KuixConstants.ALERT_QUESTION
									| KuixConstants.ALERT_YES
									| KuixConstants.ALERT_NO, "sendsms",
							"!exit");
			return false;
		}
		else if ("sendsms".equals(identifier)) {
			new SMSender(message, destination).send();
			return false;
		}
		else if ("back".equals(identifier)) {
			Kuix.getFrameHandler().removeFrame(instance);
			return false;
		} 
		return false;
	}

	public void onRemoved() {
		try {
			ContentFrame.instance.showScreen();
			screen.cleanUp();
			screen = null;
		} catch (Exception e) {
		}
	}

}
